package com.qf.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.ssm.mapper.CustomerBlackListMapper;
import com.qf.ssm.mapper.CustomerSelectMapper;
import com.qf.ssm.service.CustomerBlackListService;
import com.qf.ssm.vo.CustomerSelectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author chengqiang
 * @Create 2024-01-04-11:42
 * @Description: 黑名单业务层实例类
 */
@Service

public class CustomerBlackListServiceImpl implements CustomerBlackListService {
    @Autowired
    private CustomerBlackListMapper customerBlackListMapper;

    @Autowired
    private CustomerSelectMapper customerSelectMapper;

    @Override
    public Integer queryCustomerByIdOrder(Integer id) {
        // 查询客户是否有没完成的订单
        return customerSelectMapper.customerByIdOrder(id);
    }


    // 将客户加入黑名单
    @Override
    @Transactional
    public Integer saveCustomerBlackList(Integer id) {
        // 向客户变成已删除状态
        if (customerBlackListMapper.updateCustomerDelStatus(id) == 0) {
            return 0;
        }

        // 向客户加入黑名单
        customerBlackListMapper.insertCustomerBlackList(id);

        return 1;
    }

    // 将客户恢复黑名单
    @Override
    @Transactional
    public Integer removeCustomerBlackList(Integer id) {
        // 将客户变成未删除状态
        if (customerBlackListMapper.updateCustomerUnDelStatus(id) == 0) {
            return 0;
        }
        // 将客户拉出黑名单
        customerBlackListMapper.deleteCustomerBlackList(id);
        return 1;
    }

    @Override
    // 永久删除
    public Integer customerDeleteCompletely(Integer id) {

        return customerBlackListMapper.customerDeleteCompletely(id);
    }

    @Override
    public PageInfo<CustomerSelectVO> queryCustomerBlackListMapper(int pagNum,int pagSize) {
        return PageHelper.startPage(pagNum,pagSize).doSelectPageInfo(()->customerBlackListMapper.selectCustomerBlackList());

    }

}
